package com.jeesite.modules.app.course.answers;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.validator.constraints.Length;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.jeesite.common.entity.Page;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.mapper.JsonMapper;
import com.jeesite.modules.conf.AppController;
import com.jeesite.modules.conf.MessageCode;
import com.jeesite.modules.zx.course.answers.entity.TcourseAnswers;
import com.jeesite.modules.zx.course.answers.service.TcourseAnswersService;
import com.jeesite.modules.zx.course.question.entity.TcourseQuestion;

@Controller
@RequestMapping(value = "/app/course/answers/")
public class AppCourseAnswersController {
	@Autowired
	private TcourseAnswersService tcourseAnswersService;
	@RequestMapping(value = "findPage")
	public void findPage(TcourseAnswers entity, HttpServletRequest request,HttpServletResponse response){
		entity.setPage(new Page<>(request, response));
		Page<TcourseAnswers> findPage = tcourseAnswersService.findPage(entity);
		JSONObject json=JSONObject.parseObject(JsonMapper.toJson(findPage));
		AppController.renderSuccessObject(response, json, MessageCode.SUCCESS_ACK);
	}
	@RequestMapping(value = "save")
	public void save(TcourseAnswers entity, HttpServletRequest request,HttpServletResponse response){
		String questionId = entity.getQuestionId();
		if(StringUtils.isBlank(questionId)){
			AppController.renderErrorString(response, MessageCode.PARAMETER_IS_NEED, "问题标识");
			return;
		}
		String teacherId = entity.getTeacherId();
		if(StringUtils.isBlank(teacherId)){
			AppController.renderErrorString(response, MessageCode.PARAMETER_IS_NEED, "用户标识");
			return;
		}
		String content = entity.getContent();
		if(StringUtils.isBlank(content)){
			AppController.renderErrorString(response, MessageCode.PARAMETER_IS_NEED, "回复内容");
			return;
		}
		tcourseAnswersService.save(entity);
		AppController.renderSuccessObject(response, "", MessageCode.SUCCESS_ACK);
	}
}
